package test1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-11-02
 * Time: 11:07
 */
public class ICBCBankCard extends BankCardnew{
    final static String bankName="工商银行"; //银行名称
    static  {
        baseNum = 62224812345670001L; //设置工行起始编号
    }

    public ICBCBankCard(String uid, String uname) {
        super(uid, uname);
        this.fee = 0.01;
    }
    //为指定用户办理银行卡,并存款
    public ICBCBankCard(String uid, String uname, double firstMoney) {
        super(uid, uname, firstMoney);
        this.fee = 0.01;
    }


    @Override
    public boolean transferMoney(BankCardnew bk, double money) {
        if(bk instanceof ICBCBankCard) {  //instanceof判断左边的对象是否为右边构造函数的实例

            try {
                if( this.drawMoney(money,this.password) ) { //取款
                    bk.deposit(money); //存款
                    return true;
                } else {
                    return false;
                }
            } catch (MoneyException e) {
                System.out.println(e.getMessage());
                throw new RuntimeException(e);
            }

        } else {   //跨行转账
            double tfee =  money*this.fee;
            try {
                if( this.drawMoney(money+tfee,this.password) ) { //取款
                    bk.deposit(money); //存款
                    return true;
                } else {
                    return false;
                }
            } catch (MoneyException e) {
                System.out.println(e.getMessage());
                throw new RuntimeException(e);
            }
        }
    }

    @Override
    public String toString() {
        return "工商银行卡[" +
                "卡号 =" + cardNo +
                ", 密码 ='" + password + '\'' +
                ", 余额 =" + balance +
                ", 用户姓名 ='" + name + '\'' +
                ", 身份证号 ='" + uid + '\'' +
                ", 跨行转账费率 =" + fee +
                ']';
    }
}
